//
//  ViewController.m
//  函数的链式编程
//
//  Created by YYY on 2018/1/15.
//  Copyright © 2018年 YYY. All rights reserved.
//

#import "ViewController.h"

#import "Person.h"

#import "WYJLinkerButton.h"

typedef void(^RequestSuccess)(NSString *result);

typedef void(^RequestFail)(NSString *error);

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

    WYJLinkerButton* sender1 = [WYJLinkerButton creatButton:CGRectMake(100, 100, 100, 100)];
    sender1.ImageEdgInsets(20,0,60,60)
    .TitleEdgInsets(0,63,100,23)
    .ImagePrams(@"餐饮服务",1)
    .TitlePrams(@"餐饮服务", 17, [UIColor grayColor], 1)
    .ClickAction(sender1);
    [self.view addSubview:sender1];
    
    Person *p = [Person new];
    [p eat];
    [p sheep];

    [[p study] think];
    [[p think] study];
    
    p.smile().happy();
    p.happy().smile();
    
    p.cry(@"事不如意").crazy(10);
    p.crazy(20).cry(@"五月的烦恼");
    
    //block回调：
    [self method1:^(NSString *result) {
        NSLog(@"结果1：%@", result);
    }];
    
    [self method2:@"iPhone" complection:^(NSString *result) {
        NSLog(@"结果2：%@", result);
    }];
    
    [self method3:^(NSString *result) {
        NSLog(@"结果3：%@", result);
    } fail:^(NSString *error) {
        NSLog(@"出错1：%@", error);
    }];
    
    [self method4:@"Good luck today!" success:^(NSString *result) {
        NSLog(@"结果4：%@", result);
    } fail:^(NSString *error) {
        NSLog(@"出错2：%@", error);
    }];
}

- (void)method1:(void(^)(NSString *result))complection
{
    NSString *string = @"Happy New Year!";
    complection(string);
}

- (void)method2:(NSString *)str complection:(void(^)(NSString *result))complection
{
    NSString *string = @"What a nice day today!";
    complection(string);
}

- (void)method3:(RequestSuccess)success fail:(RequestFail)fail
{
    NSString *string = @"I'm in a good mood today!";
    if (string.length > 0)
    {
        success(string);
    }
    else
    {
        fail(@"网络出错");
    }
}

- (void)method4:(NSString *)str success:(RequestSuccess)success fail:(RequestFail)fail
{
    NSString *string = str;
    if (string.length > 0)
    {
        success(string);
    }
    else
    {
        fail(@"网络出错");
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
